﻿using DevelopTool.Common;
using DevelopTool.SafetyForms;
using Sunny.UI;
using System;
using System.Windows.Forms;

namespace DevelopTool.OffLine.Forms
{
    public partial class MainForm : UIForm
    {

        /// <summary>
        /// 登录和新用户窗体的父窗体
        /// </summary>
        // private BaseUIForm baseUIForm;

        private LogingForm logingForm;

        public MainForm()
        {
            InitializeComponent();
        }

        private void uiNavBarHeader_MenuItemClick(string itemText, int menuIndex, int pageIndex)
        {
            
            switch (itemText)
            {
                case "离线管理"://离线管理
                    break;
                  
                case "批量离线"://批量离线
                    if (!ExistPage(2))
                    {
                        AddPage(new BatchOfflineDataForm(), 2);
                    }
                    SelectPage(2);
                    break;

            }
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            WindowsHelper.SetSystemThem();//设置主题


            #region 登录或新用户


            uiNavBarHeader.Visible = false;//隐藏顶部菜单栏
            MaximizeBox = false;//隐藏放大操作按钮
            Movable = false;//设为不可拖动

            logingForm = new LogingForm(this);
            logingForm.Show(this);

            WaitLoging();

            #endregion
        }

        /// <summary>
        /// 等待登录完成
        /// </summary>
        private void WaitLoging()
        {
            Timer timer = new Timer();
            timer.Interval = 1000;
            timer.Enabled = true;
            timer.Tick += delegate (object sender, EventArgs e)
            {
                if (logingForm.IsConfirm)
                {
                    timer.Stop();
                    uiNavBarHeader.Visible = true;
                    MaximizeBox = true;
                    Movable = true;
                    logingForm.Close();
                    
                    timer.Dispose();
                }
            };
        }


    }
}
